<?php
/**
 * 焦点图管理
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: FocusModel.class.php v1.0 2014-06-23 17:27:03 $
 */
namespace Admin\Model;
class FocusModel extends CommonModel{
    protected $_link = array(
        'imgurls' => array(
            'mapping_type'  => self::HAS_MANY,
            'class_name'    => 'FocusImg',
            'foreign_key'   => 'fid'
        )
    );
    /**
     * 自动验证规则
     * @var type 
     */
    protected $_validate = array(
        array("title", "require", "焦点图标题必须填写！", 1),
        array("nid", "require", "焦点图唯一标识必须填写！", 1),
        array('nid', 'isLower', '焦点图唯一标识只能由"-"、a~z组成！', 1, 'callback'),
        array('nid', 'uniqueNid', '焦点图唯一标识已经存在！', 1 , 'callback'),
        array('adTrigger', array('click', 'mouseover'), '按钮触发切换模式选择有误！', 1 , 'in'),
        
    );
    
    protected $_auto = array(
        array("width", "intval", 3, "function"),
        array("height", "intval", 3, "function"),
        array("txtHeight", "intval", 3, "function"),
        array("times", "intval", 3, "function"),
        array("create_time", "time", 1, "function"),
    );


    public function isLower($nid) {
        if (preg_match("/^[a-z_\-0-9A-Z]+$/", $nid)) {
            return true;
        }
        return false;
    }
    /**
     * 检查焦点图唯一标识标识
     * @param type $nid
     */
    public function uniqueNid($nid) {
        return $this->isUnique("nid", $nid);
    }
    
    
    public function preUpdate($id) {
        $this->setUpdateSession('update_id', $id);
    }

    public function afterUpdate() {
        $this->unsetUpdateSession('update_id');
    }
}
